//
// Created by 谢哲 on 2021/5/17.
//

#include <iostream>
#include <map>
#include <set>
#include <string>
using namespace std;

int main() {
    int N;
    cin >> N;

    map<string, set<int>> mdata;

    for (int i=0; i<N; ++i) {
        int L;
        cin >> L;
        for (;L;--L) {
            string s;
            cin >> s;
            mdata[s].insert(i+1);
        }
    }

    int M;
    cin >> M;
    for (;M;--M) {
        string s;
        cin >> s;
        for (auto p: mdata[s]) {
            cout << p << " ";
        }
        cout << "\n";
    }

    return 0;
}
